package com.ssh.url.action;

import java.util.List;

import com.ssh.url.dao.UrlDao;
import com.ssh.url.model.Url;
import com.ssh.web.common.BaseAction;

public class SearchKeywordAction extends BaseAction {

	private static final long serialVersionUID = 39633300300790800L;

	public String search() {
		String keyword = getRequest().getParameter("keyword");
		long startTime = System.currentTimeMillis();
		List<Url> list = null;
		if ("*".equals(keyword)) {
			list = UrlDao.getList();
		} else {
			if (keyword != null && keyword.startsWith("*:")) {
				int pageSize = new Integer(keyword.split(":")[1]);
				list = UrlDao.getList(pageSize);
			} else {
				list = UrlDao.searchUrlByKeyword(keyword);
			}
		}
		long endTime = System.currentTimeMillis();
		getRequest().setAttribute("keyword", keyword);
		getRequest().setAttribute("list", list);
		getRequest().setAttribute("useTime", endTime-startTime);
		getRequest().setAttribute("count", UrlDao.getTotalCount("t_url"));
		getRequest().setAttribute("searchCount", list == null ? 0 : list.size());
		return SUCCESS;
	}
}
